<?php

namespace System\Data;

/**
 * Description of DB
 *
 * @author elton.schivei
 */
abstract class DB extends \System\Types\Object
{

    const DB2 = 'DB2';
    const FIREBIRD = 'FiBase';
    const INTERBASE = 'FiBase';
    const MYSQL = 'MySQL';
    const MYSQLI = 'MySQLi';
    const MSSQL = 'MSSQL';
    const PGSQL = 'PgSQL';

    /**
     * Only for windows
     */
    const SQLSRV = 'SQLSrv';
    const OCI8 = 'OCI8';
    const ODBC = 'ODBC';
    const SQLITE = 'SQLITE';
    const SQLITE3 = 'SQLITE3';
    const MSQL = 'MSQL';
    const INFORMIX = 'Informix';
    const INGRES = 'Ingres';
    const FRONTBASE = 'FrontBase';
    const MONGO = 'Mongo';
    const OVRIMOS = 'OvrimosSQL';
    const SYBASE = 'Sybase';
    const TOKYOTYRANT = 'TokyoTyrant';

    /**
     * Get Default Driver Connection
     *
     * @return \System\Data\IDataDriver
     */
    public static function GetDriver(\System\Core\ConfigItem $driver = null)
    {
        if (\is_null($driver))
            $driver = \config_item('driver', \CFG_DATABASE);
        else
            $driver = $driver->Valor;

        $drv = "\\System\\Data\\Drivers\\{$driver}\\Driver";

        if (!\class_exists($drv, true))
        {
            $driver = self::MYSQLI;
            $drv = "\\System\\Data\\Drivers\\{$driver}\\Driver";
        }

        return $drv::GetInstance();
    }

}
